///*
// * Copyright The OpenTelemetry Authors
// * SPDX-License-Identifier: Apache-2.0
// */
//
//package com.xiashitech.agent.instrumentation.netty.netty_v4_1.server;
//
//import com.xiashitech.agent.instrumentation.netty.netty_v4_1.AttributeKeys;
//import com.xiashitech.agent.instrumentation.netty.netty_v4_common.HttpRequestAndChannel;
//import io.netty.channel.Channel;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.ChannelInboundHandlerAdapter;
//import io.netty.handler.codec.http.HttpRequest;
//import io.netty.util.Attribute;
//import io.opentelemetry.javaagent.shaded.io.opentelemetry.context.Context;
//import io.opentelemetry.javaagent.shaded.io.opentelemetry.context.Scope;
//
//import static com.xiashitech.agent.instrumentation.netty.netty_v4_1.server.NettyServerSingletons.instrumenter;
//public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapter {
//
//  @Override
//  public void channelRead(ChannelHandlerContext ctx, Object msg) {
//    Channel channel = ctx.channel();
//    Attribute<Context> contextAttr = channel.attr(AttributeKeys.SERVER_CONTEXT);
//    Attribute<HttpRequestAndChannel> requestAttr = channel.attr(NettyServerSingletons.HTTP_REQUEST);
//
//    if (!(msg instanceof HttpRequest)) {
//      Context serverContext = contextAttr.get();
//      if (serverContext == null) {
//        ctx.fireChannelRead(msg);
//      } else {
//        try (Scope ignored = serverContext.makeCurrent()) {
//          ctx.fireChannelRead(msg);
//        }
//      }
//      return;
//    }
//
//    Context parentContext = contextAttr.get();
//    if (parentContext == null) {
//      parentContext = Context.current();
//    }
//    HttpRequestAndChannel request = HttpRequestAndChannel.create((HttpRequest) msg, channel);
//
//    if (!instrumenter().shouldStart(parentContext, request)) {
//      ctx.fireChannelRead(msg);
//      return;
//    }
//
//    Context context = instrumenter().start(parentContext, request);
//    contextAttr.set(context);
//    requestAttr.set(request);
//
//    try (Scope ignored = context.makeCurrent()) {
//      ctx.fireChannelRead(msg);
//      // the span is ended normally in HttpServerResponseTracingHandler
//    } catch (Throwable throwable) {
//      // make sure to remove the server context on end() call
//      instrumenter().end(contextAttr.getAndRemove(), requestAttr.getAndRemove(), null, throwable);
//      throw throwable;
//    }
//  }
//}
